﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using Foundation;

namespace DataHandler.Test {
    /// <summary>
    /// Stellt Werkzeuge und Methoden für die Tests zur Verfügung
    /// </summary>
    public class DataHandlerTestUtil {

        /// <summary>
        /// Da Connection Objekt auf die Datenbank
        /// </summary>
        private SQLiteConnection con; 


        /// <summary>
        /// Konstruktor. Nimmt ein Connection Objekt entgegen
        /// </summary>
        /// <param name="con">Connection Objekt, welches den Zugriff auf die Datenbank erlaubt</param>
        public DataHandlerTestUtil(SQLiteConnection con) {
            this.con = con; 
        }


        /// <summary>
        /// Zählt die Anzahl Datensätze in einer Tabelle auf der Datenbank
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public int EntityCount(EntityType type) {
            string commandText = string.Empty;
            switch (type) {
                case EntityType.SoundSuite:
                    commandText = "SELECT Count(*) FROM SoundSuite;";
                    break;
                case EntityType.EffectGroup:
                    commandText = "SELECT Count(*) FROM EffektGroup;";
                    break;
                case EntityType.Effect:
                    commandText = "SELECT Count(*) FROM Effekt;";
                    break;
                case EntityType.Track:
                    commandText = "SELECT Count(*) FROM Track;";
                    break;
                case EntityType.TrackInEffect:
                    commandText = "SELECT Count(*) FROM TrackInEffekt;";
                    break;
                case EntityType.TrackInCategorie:
                    commandText = "SELECT Count(*) FROM TrackInCategorie;";
                    break;
                case EntityType.Category: 
                    commandText = "SELECT Count(*) FROM Category;";
                    break;
            }
            SQLiteCommand cmd = this.createCommandAndOpenConnection();
            cmd.CommandText = commandText;
            return Convert.ToInt32(cmd.ExecuteScalar()); 
        }

        /// <summary>
        /// Gibt ein geöffnetes SQLiteCommand Objekt zurück, welches für die Zugriffe auf die Datenbank verwendet werden kann
        /// </summary>
        /// <returns></returns>
        internal SQLiteCommand createCommandAndOpenConnection() {
            DataBaseProperties properties = DataBaseProperties.GetInstance();
            SQLiteCommand cmd = this.con.CreateCommand();

            if (con.State != System.Data.ConnectionState.Open) {
                con.Open();
            }
            return cmd;
        }

        public List<Track> GetValidTrackList() {
            List<Track> trackList = new List<Track>();
            trackList.Add(new Track("001 - Introduction.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("002 - The City.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("003 - The Tavern.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("004 - The Quest.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("005 - At The Fair.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("006 - The Journey Begins.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("007 - Lore.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("008 - IntoTheGreen.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("009 - The Forest.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            trackList.Add(new Track("010 - Mystical Clearing.mp3", @"D:\Projekte\RpgSoundMixer2.0\TestData\TrackFolder"));
            return trackList;
        }
    }

    /// <summary>
    /// Wenn eine Entity aus der Datenbank angegeben werden muss, kann dieser Enum verwendet werden.
    /// </summary>
    public enum EntityType {
        /// <summary>
        /// SoundSuite
        /// </summary>
        SoundSuite,
        /// <summary>
        /// EffectGroup
        /// </summary>
        EffectGroup,
        /// <summary>
        /// Effect
        /// </summary>
        Effect,
        /// <summary>
        /// Track
        /// </summary>
        Track, 
        /// <summary>
        /// TrackInEffect
        /// </summary>
        TrackInEffect,
        /// <summary>
        /// TrackInCategorie
        /// </summary>
        TrackInCategorie, 
        /// <summary>
        /// Category
        /// </summary>
        Category
    }

    

}
